package com.x.Servlet_09_Session;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

/**
 * ClassName: ServletA
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.08.28 16:05
 */

@WebServlet("/TestSession1")
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");

        HttpSession session = req.getSession();

        System.out.println(session.getId());
        System.out.println(session.isNew());
        System.out.println("******************************");

        //将获取的参数存入session
        session.setAttribute("username", username);
    }
}
